package com.sky.dto;

import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.groups.Default;
import java.io.Serializable;

@Data
public class EmployeeDTO implements Serializable {

    // 关键：编辑时必须传 id，新增时无需（数据库自增）
    @NotNull(message = "编辑员工时ID不能为空", groups = UpdateGroup.class)
    private Long id;

    private String username;

    private String name;

    @NotNull(message = "手机号不能为空", groups = {Default.class, UpdateGroup.class})
    @Pattern(regexp = "^1\\d{10}$", message = "手机号格式错误（需11位数字）", groups = {Default.class, UpdateGroup.class})
    private String phone;

    @NotBlank(message = "性别不能为空", groups = {Default.class, UpdateGroup.class})
    @Pattern(regexp = "^[01]$", message = "性别非法，仅支持 0（女）或 1（男）", groups = {Default.class, UpdateGroup.class})
    private String sex;

    // 18位身份证正则：覆盖地区码、年份、月份、日期、校验位（含X/x）
    private static final String ID_CARD_REGEX ="^[1-9]\\d{5}(18|19|20)\\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\\d|3[01])\\d{3}[0-9Xx]$";
    @NotBlank(message = "身份证号不能为空", groups = {Default.class, UpdateGroup.class})
    @Pattern(regexp = ID_CARD_REGEX, message = "身份证号格式错误（支持18位，含X或x）", groups = {Default.class, UpdateGroup.class})
    private String idNumber;

}
